package cn.demoxy.controller;

import cn.demoxy.model.dto.DemoLogDTO;
import cn.demoxy.model.dto.DemoUserDTO;
import cn.demoxy.result.R;
import cn.demoxy.service.IDemoLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * @auther demo
 * @date 2022/5/18 20:13
 * 日志表控制层
 */
@Api(tags = "日志接口信息")
@RestController
@RequestMapping("/admin/demo-log")
@AllArgsConstructor
@CrossOrigin
public class DemoLogController {

    /**
     * 日志service
     */
    private IDemoLogService logService;


    /**
     * 根据条件分页查询日志列表
     *
     * @param logDTO
     * @return
     */
    @ApiOperation(value = "根据条件分页查询日志列表")
    @PostMapping("/page")
    @RequiresPermissions("demo-log:page")
    public R page(@RequestBody DemoLogDTO logDTO) {
        return R.ok(logService.findAllLogByKeyword(logDTO));
    }


    /**
     * 删除日志信息
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "删除日志信息")
    @PostMapping("/delete/{id}")
    @RequiresPermissions("demo-log:delete")
    public R removeLog(@PathVariable("id") String id) {
        return R.ok(logService.removeById(id));
    }

    /**
     * 批量删除日志信息
     *
     * @param logDTO
     * @return
     */
    @ApiOperation(value = "批量删除日志信息")
    @PostMapping("batchRemoveLogs")
    @RequiresPermissions("demo-log:batchRemove")
    public R batchRemoveLogs(@RequestBody DemoLogDTO logDTO) {
        logService.removeByIds(Arrays.asList(logDTO.getIds()));
        return R.ok();
    }
}
